package com.epi.one.basic.generic.task;

/**
 * @author dxy
 * @version 1.0
 */
public interface Task {
    void run() throws Exception;

    static <T extends Throwable> void throwAs(Throwable t) throws T {
        throw (T) t;  //T实际为捕捉的类型，比如IOException，但编译器认为T是Throwable
    }

    static Runnable asRunnable(Task task) {
        return ()->{
            try{
                task.run();
            } catch (Exception e) {
                System.out.println(e.getClass());
                Task.<RuntimeException>throwAs(e);
            }
        };
    }
}
